home *** CD-ROM | disk | FTP | other *** search
- property pStraights, pBends, pBoxes, pBoxesPos, pStraightsReset, pBendsReset, pStraightsComplete, pBendsComplete, hk, pBall, pBallRB, pPipes, pArrow, pCup, pGap, pNormalShader, pGlowShader, pNoHks, pTime, pTimeGone, pPipeActive, pPipeTotal, pPipesUsed, pAdjSlots, pLandCount, pStuckCount, pFadeState, pLevelScore, pPipeScore, pMovesLeft, pMovesMax, pLevelFailure, leftkey, rightkey, downkey, upkey, spacekey, dcam, cam, dcamCenter, pCamZoom, pCamRotate, pRotX, pRotY, pMousePrevX, pMousePrevY, pRotations, pSucker, pLoaderData, pCursorLoc, pLocNum, pCursorX, pCursorY, pCursorX2, pCursorY2, pCursorTime, pWaits, pWaitNum, pWaitStart, pInsNum, pInsAction, pActionNum, pActions, pStartTime
- global w3d, gKeyOn, gGameMode, gLevel, gScore, gSkillMode, gPrevLevel
-
- on beginSprite me
- gPrevLevel = gLevel
- gLevel = 1
- w3d = sprite(2).member
- w3d.resetWorld()
- hk = member(1)
- hk.Initialize(w3d, 1, 0.025)
- pStraights = []
- pBends = []
- pBoxes = []
- pBoxesPos = []
- pRotations = [vector(0, 0, 90), vector(90, 0, 0), vector(0, 0, 0), vector(0, 90, 0), vector(0, 180, 0), vector(0, 270, 0), vector(180, 0, 0), vector(180, 90, 0), vector(0, 0, 180), vector(180, 270, 0), vector(0, 270, 90), vector(90, 0, 0), vector(270, 0, 0), vector(0, 90, 90)]
- gLevel = 1
- loadLevel()
- getCompleteLevels()
- setupGame()
- setupObjects(me)
- setupCamera()
- end
-
- on loadLevel
- txt = member("Levels").text.line[gLevel]
- if txt.word.count < 8 then
- alert("Error loading level")
- return
- end if
- pLoaderData = []
- pLoaderData.add(vector(float(txt.word[4]), float(txt.word[5]), float(txt.word[6])))
- pLoaderData.add(vector(float(txt.word[7]), float(txt.word[8]), float(txt.word[9])))
- pLoaderData.add(integer(txt.word[3]))
- n = 10
- lim = 3
- if gLevel > 30 then
- lim = 4
- end if
- m = w3d.model[1]
- t = m.getWorldTransform()
- repeat with x = 1 to lim
- repeat with y = 1 to lim
- repeat with z = 1 to lim
- i = integer(txt.word[n])
- n = n + 1
- if (i > 0) and (i < 4) then
- m.transform = transform()
- m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
- if i <> 1 then
- m.rotate(pRotations[i - 1])
- end if
- pStraights.add(m.transform.duplicate())
- next repeat
- end if
- if (i > 3) and (i < 16) then
- m.transform = transform()
- m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
- m.rotate(pRotations[i - 1])
- pBends.add(m.transform.duplicate())
- next repeat
- end if
- if i = 16 then
- pBoxesPos.add(vector((x - 1) * 16, (y - 1) * -16, (z - 1) * -16))
- end if
- end repeat
- end repeat
- end repeat
- m.transform = t
- end
-
- on getCompleteLevels
- txt = member("LevelsComplete").text.line[gLevel]
- if txt.word.count < 8 then
- alert("Error loading complete level")
- return
- end if
- pStraightsComplete = []
- pBendsComplete = []
- n = 10
- lim = 3
- if gLevel > 30 then
- lim = 4
- end if
- m = w3d.model[1]
- t = m.getWorldTransform()
- repeat with x = 1 to lim
- repeat with y = 1 to lim
- repeat with z = 1 to lim
- i = integer(txt.word[n])
- n = n + 1
- if (i > 0) and (i < 4) then
- m.transform = transform()
- m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
- if i <> 1 then
- m.rotate(pRotations[i - 1])
- end if
- pStraightsComplete.add(m.transform.duplicate())
- next repeat
- end if
- if (i > 3) and (i < 16) then
- m.transform = transform()
- m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
- m.rotate(pRotations[i - 1])
- pBendsComplete.add(m.transform.duplicate())
- end if
- end repeat
- end repeat
- end repeat
- m.transform = t
- end
-
- on parseTransform txt
- valid = "[]-1234567890,."
- txtLen = txt.length
- repeat with i = 1 to txtLen
- if valid contains txt.char[i..i] then
- next repeat
- end if
- delete txt.char[i..i]
- i = i - 1
- txtLen = txtLen - 1
- end repeat
- return txt
- end
-
- on setupObjects me
- pGlowShader = w3d.shader("GlowGlassShader")
- pNormalShader = w3d.shader("GlassShader")
- pNormalShader.blend = 50
- pGlowShader.blend = 70
- hk.gravity = vector(0, -200, 0)
- pBall = w3d.model("Ball")
- pCup = w3d.model("Cup")
- pSucker = w3d.model("BallSucker")
- pBall.worldPosition = pLoaderData[1]
- pCup.worldPosition = pLoaderData[2]
- pSucker.transform.position = pBall.worldPosition
- if gLevel > 30 then
- w3d.model("BoxOutline").scale(1.33329999999999993, 1.33329999999999993, 1.33329999999999993)
- end if
- pPipes = []
- num = 1
- repeat with i = 1 to pStraights.count
- w3d.model("Pipe_Straight(Glass)").clone("Pipe" & num)
- m = w3d.model("Pipe" & num)
- m.transform = pStraights[i]
- pPipes.add(m)
- num = num + 1
- end repeat
- repeat with i = 1 to pBends.count
- w3d.model("Pipe_Bend(Glass)").clone("Pipe" & num)
- m = w3d.model("Pipe" & num)
- m.transform = pBends[i]
- pPipes.add(m)
- num = num + 1
- end repeat
- pPipeTotal = num - 1
- w3d.deleteModel("Pipe_Straight(Glass)")
- w3d.deleteModel("Pipe_Bend(Glass)")
- w3d.deleteModel("Glow_Bend(Glass)")
- w3d.deleteModel("Glow_Straight(Glass)")
- pPipeActive = pPipes[1]
- pPipeActive.shaderList[getShaderNum(pPipeActive)] = pGlowShader
- pBoxes = []
- repeat with i = 1 to pBoxesPos.count
- w3d.model("BoxChrome").clone("BoxChrome" & i)
- m = w3d.model("BoxChrome" & i)
- m.transform.position = pBoxesPos[i]
- pBoxes.add(m)
- end repeat
- w3d.deleteModel("BoxChrome")
- pArrow = [w3d.model("Arrow")]
- pArrow[1].scale(1.5)
- pArrow[1].pointAtOrientation = [vector(0, 1, 0), vector(1, 0, 0)]
- repeat with i = 1 to 5
- b = w3d.model("Arrow").clone("Arrow" & i)
- b.pointAtOrientation = [vector(0, 1, 0), vector(1, 0, 0)]
- pArrow.add(b)
- end repeat
- setArrows()
- bf = w3d.newTexture("BlackFade", #fromCastMember, member("black"))
- w3d.camera[1].addOverlay(bf, point(0, 0), 0)
- w3d.camera[1].overlay[1].scale = 840
- w3d.camera[1].overlay[1].blend = 100
- bf = w3d.newTexture("Cursor", #fromCastMember, member("cursor"))
- w3d.camera[1].addOverlay(bf, point(0, 0), 0)
- w3d.camera[1].overlay[2].blend = 100
- w3d.camera[1].overlay[2].loc = pCursorLoc[1]
- end
-
- on setPipes setType
- if setType = "start" then
- straights = pStraights
- bends = pBends
- else
- if setType = "complete" then
- straights = pStraightsComplete
- bends = pBendsComplete
- else
- if setType = "back" then
- straights = pStraightsReset
- bends = pBendsReset
- end if
- end if
- end if
- pStraightsReset = []
- pBendsReset = []
- num = 1
- repeat with i = 1 to pStraights.count
- m = w3d.model("Pipe" & num)
- pStraightsReset[i] = m.getWorldTransform()
- m.transform = straights[i]
- num = num + 1
- end repeat
- repeat with i = 1 to pBends.count
- m = w3d.model("Pipe" & num)
- pBendsReset[i] = m.getWorldTransform()
- m.transform = bends[i]
- num = num + 1
- end repeat
- setArrows()
- end
-
- on getShaderNum pipe
- if string(pipe.resource.name).length < 20 then
- return 2
- else
- return 1
- end if
- end
-
- on makeHK
- pPipeActive.shaderList[getShaderNum(pPipeActive)] = pNormalShader
- repeat with i = 1 to 6
- pArrow[i].transform.position = vector(0, 1000, 0)
- end repeat
- pNoHks = ["Ball", "Marker"]
- pBall.addModifier(#meshDeform)
- pBallRB = hk.makeMovableRigidBody(pBall.name, 1, 1, #sphere)
- pBallRB.restitution = 0.20000000000000001
- pBallRB.friction = 0.80000000000000004
- pBallRB.linearVelocity = vector(0, 0, 0)
- pBallRB.angularVelocity = vector(0, 0, 0)
- pCup.addModifier(#meshDeform)
- rb = hk.makeFixedRigidBody(pCup.name, 0)
- rb.restitution = 0.0
- rb.friction = 0.80000000000000004
- repeat with i = 1 to pPipes.count
- pPipes[i].addModifier(#meshDeform)
- rb = hk.makeFixedRigidBody(pPipes[i].name, 0)
- rb.restitution = 0.0
- rb.friction = 0.80000000000000004
- end repeat
- pGap = []
- m = w3d.model[1]
- t = m.getWorldTransform()
- lim = 3
- if gLevel > 30 then
- lim = 4
- end if
- repeat with x = 1 to lim
- repeat with y = 1 to lim
- repeat with z = 1 to lim
- m.transform = transform()
- m.translate((x - 1) * 16, (y - 1) * -16, (z - 1) * -16)
- foundPipe = 0
- repeat with p in pPipes
- dPipe = m.worldPosition.distanceTo(p.worldPosition)
- if dPipe < 5 then
- foundPipe = 1
- end if
- end repeat
- if not foundPipe then
- pGap.add(m.worldPosition)
- end if
- end repeat
- end repeat
- end repeat
- m.transform = t
- soundFX("drop", 3, 255)
- mend = member("roll").duration
- sound(2).volume = 0
- sound(2).play([#member: member("roll"), #startTime: 0, #endTime: mend, #loopStartTime: 0, #loopEndTime: mend, #loopCount: 1000])
- gGameMode = #drop
- end
-
- on setupGame
- pTime = the timer
- pAdjSlots = [vector(16, 0, 0), vector(-16, 0, 0), vector(0, 16, 0), vector(0, -16, 0), vector(0, 0, 16), vector(0, 0, -16)]
- pLandCount = 0
- pStuckCount = 0
- pLevelScore = 0
- pPipeScore = 0
- pMovesMax = pLoaderData[3]
- if gSkillMode < 3 then
- pMovesLeft = pMovesMax * 2
- else
- pMovesLeft = pMovesMax
- end if
- pPipesUsed = 0
- pFadeState = #up
- pLevelFailure = 0
- setVariable(sprite(1), "score", string(gScore))
- setVariable(sprite(1), "level", string(gLevel))
- setVariable(sprite(1), "movesLeft", string(pMovesLeft))
- moveFlash("ins")
- pActionNum = 1
- pActions = [#waitAction, #cursor, #waitAction, #cursor, #waitAction, #cursor, #waitAction, #changePipe, #waitAction, #cursor, #waitAction, #movePipe, #waitAction, #cursor, #waitAction, #insAction, #waitAction, #reset, #waitAction, #insAction, #waitAction, #hint, #waitAction, #insAction, #waitAction, #continue, #waitAction, #cursor, #waitAction, #movePipe, #waitAction, #cursor, #waitAction, #insAction, #waitAction, #dropbutton]
- pWaits = [17, 4, 3, 1, 7, 2, 7, 0, 100, 4, 100, 3, 100, 100, 1, 3, 0, 100]
- pWaitNum = 1
- pWaitStart = the timer
- pLocNum = 2
- pCursorLoc = [point(300, 400), point(100, 600), point(400, 601), point(650, 340), point(640, 580), point(838, 620), point(500, 390), point(838, 460)]
- pInsNum = 1
- pInsAction = ["reset", "hint", "continue", "dropball"]
- gGameMode = pActions[pActionNum]
- pStartTime = the timer
- gMenuCalled = 0
- flashSFX()
- end
-
- on enterFrame
- if ((the timer - pStartTime) / 60.0) > 3.70000000000000018 then
- pStartTime = the timer + (60 * 10000)
- mend = member("InsMusic").duration
- sound(7).volume = 50
- sound(7).play([#member: member("InsMusic"), #startTime: 2500, #endTime: mend, #loopStartTime: 0, #loopEndTime: mend, #loopCount: 1000])
- end if
- prevMode = gGameMode
- if gGameMode = #dropbutton then
- makeHK()
- gGameMode = #drop
- else
- if gGameMode = #drop then
- checkDrop()
- else
- if gGameMode = #waitAction then
- waitAction()
- else
- if gGameMode = #insAction then
- insAction()
- else
- if gGameMode = #cursor then
- moveCursor()
- else
- if gGameMode = #changePipe then
- changePipe()
- else
- if gGameMode = #movePipe then
- movePipe()
- else
- if gGameMode = #reset then
- setPipes("start")
- pActionNum = pActionNum + 2
- pWaitNum = pWaitNum + 1
- gGameMode = pActions[pActionNum]
- if gGameMode = #waitAction then
- pWaitStart = the timer
- end if
- else
- if gGameMode = #hint then
- setPipes("complete")
- put "CALLED COMPLETE************"
- pActionNum = pActionNum + 2
- pWaitNum = pWaitNum + 1
- gGameMode = pActions[pActionNum]
- if gGameMode = #waitAction then
- pWaitStart = the timer
- end if
- else
- if gGameMode = #hintend then
- setPipes("start")
- pActionNum = pActionNum + 2
- pWaitNum = pWaitNum + 1
- gGameMode = pActions[pActionNum]
- if gGameMode = #waitAction then
- pWaitStart = the timer
- end if
- else
- if gGameMode = #cursor28 then
- pActionNum = pActionNum + 1
- pWaitNum = pWaitNum + 1
- gGameMode = pActions[pActionNum]
- pCursorX = (pCursorLoc[pLocNum][1] - pCursorLoc[pLocNum - 1][1]) / 70.0
- pCursorY = (pCursorLoc[pLocNum][2] - pCursorLoc[pLocNum - 1][2]) / 70.0
- pCursorX2 = 0
- pCursorY2 = 0
- if gGameMode = #waitAction then
- pWaitStart = the timer
- end if
- else
- if gGameMode = #finish then
- if pFadeState <> #down then
- pFadeState = #down
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- updateCamera()
- if pFadeState <> #none then
- fadeLevel()
- end if
- pCursorTime = the milliSeconds
- end
-
- on waitAction
- if ((the timer - pWaitStart) / 60.0) > pWaits[pWaitNum] then
- pActionNum = pActionNum + 1
- pWaitNum = pWaitNum + 1
- gGameMode = pActions[pActionNum]
- if gGameMode = #cursor then
- pCursorX = (pCursorLoc[pLocNum][1] - pCursorLoc[pLocNum - 1][1]) / 70.0
- pCursorY = (pCursorLoc[pLocNum][2] - pCursorLoc[pLocNum - 1][2]) / 70.0
- put pCursorX, pCursorY
- pCursorX2 = 0
- pCursorY2 = 0
- if pActionNum = 4 then
- pCamRotate = 1
- pt = w3d.camera[1].overlay[2].loc
- pMousePrevX = pt[1]
- pMousePrevY = pt[2]
- pRotX = 0
- pRotY = 0
- end if
- end if
- end if
- end
-
- on insAction
- setVariable(sprite(1), "insAction", pInsAction[pInsNum])
- pInsNum = pInsNum + 1
- pActionNum = pActionNum + 1
- gGameMode = pActions[pActionNum]
- if gGameMode = #waitAction then
- pWaitStart = the timer
- end if
- end
-
- on moveCursor
- t = (the milliSeconds - pCursorTime) / 20.0
- put t
- pt = w3d.camera[1].overlay[2].loc
- arrived = 0
- if ((pCursorX > 0) and (pt[1] >= pCursorLoc[pLocNum][1])) or ((pCursorX < 0) and (pt[1] <= pCursorLoc[pLocNum][1])) then
- arrived = arrived + 1
- else
- if pCursorX < 1 then
- pCursorX2 = pCursorX2 + (pCursorX * t)
- if (pCursorX2 > 1) or (pCursorX2 < -1) then
- pt[1] = pt[1] + pCursorX2
- pCursorX2 = 0
- end if
- else
- pt[1] = pt[1] + (pCursorX * t)
- end if
- end if
- if ((pCursorY > 0) and (pt[2] >= pCursorLoc[pLocNum][2])) or ((pCursorY < 0) and (pt[2] <= pCursorLoc[pLocNum][2])) then
- arrived = arrived + 1
- else
- if pCursorY < 1 then
- pCursorY2 = pCursorY2 + (pCursorY * t)
- if (pCursorY2 > 1) or (pCursorY2 < -1) then
- pt[2] = pt[2] + pCursorY2
- pCursorY2 = 0
- end if
- else
- pt[2] = pt[2] + (pCursorY * t)
- end if
- end if
- if arrived = 2 then
- w3d.camera[1].overlay[2].loc = pCursorLoc[pLocNum]
- pLocNum = pLocNum + 1
- pActionNum = pActionNum + 1
- gGameMode = pActions[pActionNum]
- if gGameMode = #waitAction then
- pWaitStart = the timer
- end if
- if pCamRotate then
- pCamRotate = 0
- end if
- put "arrived @ " & pActionNum
- else
- w3d.camera[1].overlay[2].loc = pt
- end if
- if pCamRotate then
- pRotX = (pt[1] - pMousePrevX) * 0.5
- pRotY = (pt[2] - pMousePrevY) * 0.5
- pMousePrevX = pt[1]
- pMousePrevY = pt[2]
- if pRotX > 10 then
- pRotX = 10
- else
- if pRotX < -10 then
- pRotX = -10
- end if
- end if
- if pRotY > 10 then
- pRotY = 10
- else
- if pRotY < -10 then
- pRotY = -10
- end if
- end if
- end if
- end
-
- on changePipe
- pPipeActive.shaderList[getShaderNum(pPipeActive)] = pNormalShader
- pPipeActive = pPipes[3]
- pPipeActive.shaderList[getShaderNum(pPipeActive)] = pGlowShader
- setArrows()
- soundFX("choose", 3, 100)
- pActionNum = pActionNum + 1
- gGameMode = pActions[pActionNum]
- if gGameMode = #waitAction then
- pWaitStart = the timer
- end if
- end
-
- on movePipe
- if pActionNum < 20 then
- pPipeActive.worldPosition = pArrow[3].worldPosition
- else
- pPipeActive.worldPosition = pArrow[4].worldPosition
- end if
- setArrows()
- soundFX("click", 3, 50)
- pActionNum = pActionNum + 1
- gGameMode = pActions[pActionNum]
- if gGameMode = #waitAction then
- pWaitStart = the timer
- end if
- end
-
- on checkDrop
- pos = pBall.worldPosition
- vel = pBallRB.linearVelocity.magnitude
- sound(2).volume = vel
- if vel < 5 then
- pStuckCount = pStuckCount + 1
- else
- pStuckCount = 0
- end if
- repeat with p in pPipes
- dPipe = pos.distanceTo(p.worldPosition)
- ps = p.shaderList[getShaderNum(p)].name
- if (dPipe < 10) and (ps = "GlassShader") then
- soundFX("light", 3, 100)
- pPipesUsed = pPipesUsed + 1
- p.shaderList[getShaderNum(p)] = pGlowShader
- end if
- end repeat
- if gSkillMode > 1 then
- repeat with p in pGap
- dGap = pos.distanceTo(p)
- if dGap < 10 then
- pLevelFailure = 1
- end if
- end repeat
- end if
- dCup = pos.distanceTo(pCup.worldPosition)
- if dCup < 12 then
- pLandCount = pLandCount + 1
- end if
- if (pLandCount > 0) and (pLandCount < 50) then
- dy = pos.y - pCup.worldPosition.y
- if dy < 0 then
- soundFX("land", 3, 100)
- sound(2).stop()
- pLandCount = 50
- end if
- end if
- if pLandCount > 70 then
- pFadeState = #down
- gGameMode = #finish
- end if
- dy = pCup.worldPosition.y - pos.y
- if (dy > 500) or (pStuckCount > 100) then
- pLevelFailure = 1
- pFadeState = #down
- gGameMode = #finish
- end if
- end
-
- on setArrows
- repeat with i = 1 to 6
- pArrow[i].transform.position = vector(0, 1000, 0)
- end repeat
- arrowNum = 1
- p = pPipeActive.worldPosition
- if gLevel < 31 then
- upperLimit = 33
- else
- upperLimit = 49
- end if
- repeat with i in pAdjSlots
- pos = p + i
- if (pos.x < upperLimit) and (pos.x > -1) and (pos.y < 1) and (pos.y > -upperLimit) and (pos.z < 1) and (pos.z > -upperLimit) then
- blocked = 0
- repeat with b in pPipes
- d = (pos - b.worldPosition).magnitude
- if d < 1 then
- blocked = 1
- end if
- end repeat
- repeat with b in pBoxes
- d = (pos - b.worldPosition).magnitude
- if d < 1 then
- blocked = 1
- end if
- end repeat
- if not blocked then
- pArrow[arrowNum].transform.position = pos
- pArrow[arrowNum].translate(0.01, 0.01, 0.01)
- pArrow[arrowNum].pointAt(p + (i * 2), vector(0, 1, 0))
- pArrow[arrowNum].transform.position = pos
- arrowNum = arrowNum + 1
- end if
- end if
- end repeat
- end
-
- on fadeLevel
- f = cam.overlay[1].blend
- if pFadeState = #up then
- if f > 0 then
- cam.overlay[1].blend = f - 5
- else
- cam.overlay[1].blend = 0
- pFadeState = #none
- end if
- else
- if pFadeState = #down then
- if f < 100 then
- cam.overlay[1].blend = f + 5
- else
- cam.overlay[1].blend = 100
- pFadeState = #none
- endOfLevel()
- end if
- end if
- end if
- end
-
- on endOfLevel
- repeat with i = 1 to 8
- sound(i).stop()
- end repeat
- go(the frame + 1)
- end
-
- on setupCamera
- cam = w3d.camera[1]
- cam.fieldOfView = 50
- dcam = w3d.newModel("dummyCam")
- dcamCenter = w3d.newModel("dummyCenter")
- if gLevel < 31 then
- dcamCenter.transform.position = vector(16, -16, -16)
- pCamZoom = 60
- else
- dcamCenter.transform.position = vector(24, -24, -24)
- pCamZoom = 80
- end if
- dcamCenter.addChild(dcam, #preserveParent)
- dcam.translate(-pCamZoom, 0, -pCamZoom)
- pRotX = 0
- pRotY = 0
- end
-
- on updateCamera
- dcam.transform.position.z = pCamZoom
- dcam.transform.position.x = pCamZoom
- if pCamRotate then
- dcamCenter.rotate(0, -pRotX, 0)
- dcam.rotate(dcamCenter.worldPosition, vector(0, 0, 1), -pRotY * 2, #self)
- end if
- if abs(dcam.worldPosition.y + 16) > 85 then
- dcam.rotate(dcamCenter.worldPosition, vector(0, 0, 1), pRotY * 2.20000000000000018, #self)
- end if
- dcam.pointAt(dcamCenter.worldPosition, vector(0, 1, 0))
- camBuffer = 20
- cam.transform.interpolateTo(dcam.getWorldTransform(), camBuffer)
- end
-
- on endSprite me
- hk.shutDown()
- w3d.resetWorld()
- end
-